package com.hzvictory.hotel_system.service.Impl;

import com.hzvictory.hotel_system.common.properties.AliOssProperties;
import com.hzvictory.hotel_system.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import com.hzvictory.hotel_system.common.utils.AliOssUtil;
/**
 * 功能
 * 作者：何征
 * 日期：2025/8/11 15:56
 */
@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private AliOssUtil aliOssUtil;
    @Override
    public String uploadFile(MultipartFile file) {

        try {
            // 获取文件字节数组
            byte[] bytes = file.getBytes();

            // 生成文件名（可以自定义命名规则，避免重复）
            String originalFilename = file.getOriginalFilename();
            String objectName = "upload/" + System.currentTimeMillis() + "_" + originalFilename;

            // 调用工具类上传
            return aliOssUtil.upload(bytes, objectName);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("文件上传失败");
        }
    }
}
